package org.footballmanager.pandafootball.system.controller.hy;

import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.controller.BaseController;
import org.footballmanager.pandafootball.system.form.impl.FootLySearchForm;
import org.footballmanager.pandafootball.system.service.FootLyService;
import org.footballmanager.pandafootball.system.service.FootUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

@Controller
@SessionAttributes("footLySearchForm")
@RequestMapping("/hy/footLy")
public class HyLyController extends BaseController {
    /* 实体名称 */
    private static final String ENTITYNAME = "footLy";
    private static final String LISTPAGE = String.format(Constants.LISTPAGE, Constants.HY, ENTITYNAME);

    @Autowired
    private FootLyService footLyService;

    @Autowired
    private FootUserService footUserService;

    /**
     * 初始化
     *
     * @param map              参数
     * @param footLySearchForm 条件参数
     */
    @ModelAttribute
    public void init(Model map, @ModelAttribute FootLySearchForm footLySearchForm) {
        map.addAttribute("userList", footUserService.getall());
        FootLySearchForm newFootLySearchForm = new FootLySearchForm();
        if (footLySearchForm != null) {
            newFootLySearchForm = footLySearchForm;
        }
        map.addAttribute(String.format(Constants.FORMNAME, ENTITYNAME), newFootLySearchForm);
    }

    @RequestMapping(value = "/search")
    public String search(Model map, @ModelAttribute FootLySearchForm footLySearchForm) {
        footLyService.search(ENTITYNAME, map, footLySearchForm);
        return LISTPAGE;
    }

}
